package com.test.util;

import java.util.HashMap;
import java.util.Map;

import com.test.clyq.entity.VisitLogsStats;

public class ChartsUtils {

	/**
	 * 获取并赋值每小时的数量
	 * 
	 * @param currentTimeMillis
	 * @param visitLogStats
	 * @param mapValue
	 * @return
	 */
	public static Map<String, Integer> getMapDayValue(long currentTimeMillis, int dayNum, VisitLogsStats visitLogStats, Map<String, Integer> mapValue) {
		long entityItemTimeMillis = visitLogStats.getVisitTime();
		long one_time = 24 * 60 * 60 * 1000;
		for (int i = 0; i < dayNum; i++) {
			long m_time = i * 24 * 60 * 60 * 1000;
			if (entityItemTimeMillis > (currentTimeMillis + m_time) && entityItemTimeMillis < (currentTimeMillis + (m_time + one_time))) {
				String dateStr = DateUtils.longToDateString((currentTimeMillis + m_time), "yyyy-MM-dd");
				int lastValue = mapValue.get(dateStr);
				mapValue.put(dateStr, (lastValue + 1));
				break;
			}

		}
		return mapValue;
	}

	/**
	 * 获取并赋值每小时的数量
	 * 
	 * @param currentTimeMillis
	 * @param visitLogStats
	 * @param mapValue
	 * @return
	 */
	public static Map<String, Integer> getMapValue(long currentTimeMillis, VisitLogsStats visitLogStats, Map<String, Integer> mapValue) {
		long entityItemTimeMillis = visitLogStats.getVisitTime();
		long one_time = 30 * 60 * 1000;
		/** 这个地方的初始值为1，而别的地方的统计为0，其实没有却别，只是为了在这个地方好用于统计而定 */
		for (int i = 1; i <= 48; i++) {
			long m_time = i * 30 * 60 * 1000;
			if (entityItemTimeMillis > (currentTimeMillis + (m_time - one_time)) && entityItemTimeMillis < (currentTimeMillis + m_time)) {
				if (i > 20) {
					if ((i % 2) == 1) {
						String tmp_name = ((i - 1) / 2) + ":00";
						int lastValue = mapValue.get(tmp_name);
						mapValue.put(tmp_name, (lastValue + 1));
					} else {
						String tmp_name = ((i - 1) / 2) + ":30";
						int lastValue = mapValue.get(tmp_name);
						mapValue.put(tmp_name, (lastValue + 1));
					}
				} else {
					if ((i % 2) == 1) {
						String tmp_name = "0" + ((i - 1) / 2) + ":00";
						int lastValue = mapValue.get(tmp_name);
						mapValue.put(tmp_name, (lastValue + 1));
					} else {
						String tmp_name = "0" + ((i - 1) / 2) + ":30";
						int lastValue = mapValue.get(tmp_name);
						mapValue.put(tmp_name, (lastValue + 1));
					}
				}

				break;
			}

		}
		return mapValue;
	}

	public static Map<String, Integer> initMapValue(Map<String, Integer> mapValue) {
		mapValue = new HashMap<String, Integer>();
		for (int timeLong = 0; timeLong < 48; timeLong++) {
			if (timeLong > 19) {
				if ((timeLong % 2) == 0) {
					mapValue.put(((timeLong / 2) + ":00"), 0);
				} else {
					mapValue.put(((timeLong / 2) + ":30"), 0);
				}
			} else {
				if ((timeLong % 2) == 0) {
					mapValue.put(("0" + (timeLong / 2) + ":00"), 0);
				} else {
					mapValue.put(("0" + (timeLong / 2) + ":30"), 0);
				}
			}
		}
		return mapValue;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
